package com.example.demo.pattern.mixpattern;

import com.example.demo.pattern.mixpattern.entity.counter.QuackCounter;
import com.example.demo.pattern.mixpattern.entity.duck.QuackAble;
import com.example.demo.pattern.mixpattern.entity.flock.Flock;
import com.example.demo.pattern.mixpattern.factory.CountingDuckFactory;
import com.example.demo.pattern.mixpattern.observer.Quackologist;

public class Start {
    public static void main(String[] args) {
        //工厂创建鸭子
        CountingDuckFactory countingDuckFactory = new CountingDuckFactory();
        QuackAble mallardDuck = countingDuckFactory.createMallardDuck();
        QuackAble redHeadDuck = countingDuckFactory.createRedHeadDuck();
        QuackAble rubberDuck = countingDuckFactory.createRubberDuck();
        QuackAble duckCall = countingDuckFactory.createDuckCall();

        //创建一个族群
        Flock flock = new Flock();
        flock.addQuackAble(countingDuckFactory.createMallardDuck());
        flock.addQuackAble(countingDuckFactory.createMallardDuck());
        flock.addQuackAble(countingDuckFactory.createDuckCall());

        //注册观察者
        Quackologist quackologist = new Quackologist();
        flock.registerObserver(quackologist);
        rubberDuck.registerObserver(quackologist);

        System.out.println("=======rubberDuck quack=======");
        rubberDuck.quack();
        System.out.println("=======rubberDuck quack=======");

        System.out.println("=======flock quack=======");
        flock.quack();
        System.out.println("=======flock quack=======");

        System.out.println("number of Quacks:" + QuackCounter.getNumberOfQuacks());
    }
}
